import request from '@/request/request'
import axios from "axios";

/**
 * 文件上传API
 * @param {File} file - 要上传的文件
 * @param {String} type - 文件类型，可选值：avatar, product, other
 * @returns {Promise} - 返回上传结果
 */
export function uploadFile(file, type = 'other') {
  const formData = new FormData()
  console.log('上传文件名:', file.name)
  formData.append('file', file)
  formData.append('type', type)

  return request({
    url: '/api/file/upload',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}
